<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>内部浏览器</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        body,
        html {
            background: #f2f2f2;
        }

        header {
            height: 65px;
            background: #fff;
            border-bottom: 1px solid #f2f2f2;
        }

        header div {
            position: absolute;
            bottom: 0px;
            box-sizing: border-box;
            padding-left: 21px;
            width: 60px;
            height: 40px;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            -webkit-box-align: center;
            -webkit-align-items: center;
            align-items: center;
        }

        header div img {
            width: 15px;
            height: 15px;
        }

        header p {
            font-size: 1.2rem;
            color: #333;
            position: absolute;
            bottom: 6px;
            left: 50%;
            transform: translateX(-50%);
        }

        .right {
            right: 16px;
            top: 26px;
            font-size: 16px;
        }
    </style>
</head>

<body>
    <header id="app">
        <div tapmode @click="back()">
            <img src="../image/return.png" alt="">
        </div>
        <p id='top'>任务</p>
        <div class="right" tapmode onclick="closeWinD()">
            关闭
        </div>
    </header>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/app.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
<script type="text/javascript">
    var vm
    apiready = function () {
        new Vue({
            el: '#app',
            data() {
                return {
                }
            },
            methods: {
                back() {
                    var browser = api.require('webBrowser');
                    browser.historyBack(
                        function (ret, err) {
                            if (!ret.status) {
                                api.closeWin();
                            }
                        }
                    );
                }
            }
        })

        let url = api.pageParam.url 
        // let url = 'http://172.17.1.120:8080/igameh5/#/home?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ7XCJhY2NvdW50X2lkXCI6Mjk3OTUzMCxcImFwcF9pZFwiOjExNzQ2MzYxMjksXCJhcHBfa2V5XCI6MTQyNzkzMDY5LFwiZGV2aWNlXCI6XCJhbmRyb2lkXCIsXCJkZXZpY2VfaW5mb1wiOlwiODY5NTk2MDQxNjE3ODUwXCIsXCJub3RpZnlfdXJsXCI6XCJcIixcInNka0V4Y2hhbmdlXCI6XCIxLjAwXCIsXCJ0YXJnZXRfaWRcIjpcIjIwMjAxMjM3XCJ9In0.2TBHqIEWk7-zBwZQQxkHr4Hs0nh3ZDCfP6TPpIFBKtY'
        // let js = '(function(){' + JSON.stringify(asd) + '(' + JSON.stringify(data) + ')})()'
      
        api.openFrame({
            name: 'detailframeweb',
            url:url,
            rect: {
                x: 0,
                y: 65,
                w: 'auto',
            }
        });
        api.addEventListener({
            name: 'comm'
        }, function (ret, err) {
            let res = ret.value;
            switch (res.method) {
                case "jumpapp":
                    //传给h5的数据
                    let data = JSON.stringify({
                        method: 'jumpapp',
                        data: {},
                        id: res.method + new Date().getTime()
                    })
                    let js = `(function(){${res.id}(${data})})()`;
                    console.log(js, data)
                    api.execScript({
                        frameName: 'detailframeweb',
                        script: js
                    });
                    break;
                case "openBrowser":
                    api.openApp({
                        // androidPkg: 'android.intent.action.VIEW',
                        // mimeType: 'text/html',
                        uri: res.data.url
                    }, function (ret, err) {
                        // var msg = JSON.stringify(ret);
                        // api.alert({
                        //     title: 'openApp',
                        //     msg: msg,
                        //     buttons: ['确定']
                        // });
                    });
                    break;
                default:
            }
        })

    }
    function openApp() {

    }


</script>

</html>